{% extends 'base.html' %}

{% block title %}我的订单{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <h2>我的订单</h2>
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>订单号</th>
                        <th>餐厅</th>
                        <th>订单状态</th>
                        <th>总金额</th>
                        <th>下单时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for order in orders %}
                    <tr>
                        <td>{{ order.id }}</td>
                        <td>{{ order.restaurant.name }}</td>
                        <td>{{ order.get_status_display }}</td>
                        <td>¥{{ order.total_amount }}</td>
                        <td>{{ order.created_at|date:"Y-m-d H:i" }}</td>
                        <td>
                            <a href="{% url 'order_detail' order.id %}" class="btn btn-sm btn-info">查看详情</a>
                            {% if order.status == 'pending' %}
                            <form method="post" action="{% url 'cancel_order' order.id %}" class="d-inline">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-sm btn-danger">取消订单</button>
                            </form>
                            {% endif %}
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="6" class="text-center">暂无订单</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
